package com.bazaaroid.server.gae.core.persistence.model.partner;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.bazaaroid.server.gae.core.persistence.model.AbstractModel;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Partner extends AbstractModel {

	@Persistent
	private String name;
	@Persistent
	private String description;
	@Persistent
	private String imagePath;

	@Persistent(defaultFetchGroup = "true")
	@Embedded
	private Contact contact;

	@Persistent(mappedBy = "partner")
	@Element(dependent = "true")
	private List<Location> locations = new ArrayList<Location>();

	@Persistent(mappedBy = "partner")
	@Element(dependent = "true")
	private List<Product> products = new ArrayList<Product>();

	public Partner() {}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public List<Location> getLocations() {
		return locations;
	}

	public void setLocations(List<Location> locations) {
		this.locations = locations;
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public void addLocation(Location location) {
		locations.add(location);
		location.setPartner(this);
    }

	public void addProduct(Product product) {
		products.add(product);
		product.setPartner(this);
	}
}
